import { getPlayList, setPlayList} from '@/util/utils.js'

const play = {
	state: {
		playList: {
			isSearch: false,
			playState: false,	// 播放状态
			curSong: {},	// 当前播放歌曲
			list: [], // 播放列表
		}	
	},
	mutations: {
		SET_PLAY_LIST: (state, payload) => {
			if (payload.curSong && state.playList.curSong.id === payload.curSong.id) {
				let curSong = state.playList.curSong;
				curSong = Object.assign({}, curSong, payload.curSong)
				state.playList = Object.assign({}, state.playList, payload);
				state.playList.curSong = curSong;
			} else {
				state.playList = Object.assign({}, state.playList, payload);
			}
			
			// #ifdef H5
			uni.setStorageSync('uni-play-list', state.playList)
			// #endif
		}
	},

	actions: {
		// 设置播放列表
		setPlayList({commit,state}, payload) {
			commit('SET_PLAY_LIST', payload);
		},
	}
};

export default play;


// #ifdef H5
let playList = uni.getStorageSync('uni-play-list')
if (playList) {
	play.state.playList =  playList;
}
// #endif


